//=============================================================================
#include "AppStateManager.h"

// Refer to your Other App States Here
#include "AppStateIntro.h"
#include "AppStateGame.h"
#include "AppStateMenu.h"
#include "AppStateLobby.h"
#include "AppStateServer.h"
#include "AppStateCredits.h"

//=============================================================================
CAppState* CAppStateManager::ActiveAppState = 0;
int CAppStateManager::ActiveAppStateInt = 0;

//=============================================================================
void CAppStateManager::OnEvent(SDL_Event* EventHolder) {
	if(ActiveAppState) ActiveAppState->OnEvent(EventHolder);
}

//-----------------------------------------------------------------------------
void CAppStateManager::OnLoop() {
	if(ActiveAppState) ActiveAppState->OnLoop();
}

//-----------------------------------------------------------------------------
void CAppStateManager::OnRender(SDL_Surface* Surf_Display) {
	if(ActiveAppState) ActiveAppState->OnRender(Surf_Display);
}

//=============================================================================
void CAppStateManager::SetActiveAppState(int AppStateID) {
	if(ActiveAppState) ActiveAppState->OnDeactivate();

	// Also, add your App State Here so that the Manager can switch to it
	if(AppStateID == APPSTATE_NONE)		
		ActiveAppState = 0;
	if(AppStateID == APPSTATE_INTRO)	
		ActiveAppState = CAppStateIntro::GetInstance();
	if(AppStateID == APPSTATE_MENU)		
		ActiveAppState = CAppStateMenu::GetInstance();
	if(AppStateID == APPSTATE_GAME){
		ActiveAppState = CAppStateGame::GetInstance();
		ActiveAppStateInt = 3;
	}
	if(AppStateID == APPSTATE_LOBBY)		
		ActiveAppState = CAppStateLobby::GetInstance();
	if(AppStateID == APPSTATE_SERVER)
	{
		ActiveAppState = CAppStateServer::GetInstance();
		ActiveAppStateInt = 5;
	}
	if(AppStateID == APPSTATE_CREDITS)
		ActiveAppState = AppStateCredits::GetInstance();

	if(ActiveAppState) ActiveAppState->OnActivate();
}

//-----------------------------------------------------------------------------
CAppState* CAppStateManager::GetActiveAppState() {
	return ActiveAppState;
}

int CAppStateManager::GetActiveAppStateInt()
{
	return ActiveAppStateInt;
}

//=============================================================================
